﻿using System;
using System.Collections.Generic;
using System.Linq;
using ThumpThumpBus.Models.Domain;

namespace ThumpThumpBus.Models.Repository
{
    public class PersonRepository
    {
        public static List<Person> People { get { return _people.ToList(); } }

        private static readonly List<Person> _people = new List<Person>
                          {
                              new Person {id = 1, name = "Shawn Meyer"},
                              new Person {id = 2, name = "Eric Kaufman"},
                              new Person {id = 3, name = "Chad Angerer"},
                              new Person {id = 4, name = "Jed Piper"},
                              new Person {id = 5, name = "Benjamin Hansen"}
                          };

        public void AddPerson(Person person)
        {
            _people.Add(person);
        }

        public void DeletePersonById(int id)
        {
            _people.RemoveAll(p => p.id == id);
        }

        public IEnumerable<Person> GetAllPeople()
        {
            return _people;
        }

        public Person GetPersonById(int id)
        {
            return _people.Find(p => p.id == id);
        }

        public void UpdatePerson(Person person)
        {
            int index = _people.FindIndex(p => p.id == person.id);
            _people.RemoveAt(index);
        }
    }
}